/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.biblioteca.controller;

import br.com.biblioteca.utils.ServletUtils;
import br.com.biblioteca.vo.User;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author joaosavio
 */
public class AuthenticationFilter implements IFilter {

    public void execute(HttpServletRequest request, HttpServletResponse response) {
        String req = request.getRequestURI();
        System.out.println(req);
        if (req.contains(Page.INDEX) || (req.contains("service=UserService") && req.contains("action=login"))) {
            return;
        }

        HttpSession session = request.getSession(false);
        if (session == null) {
            ServletUtils.dispatcher(request, response, Page.INDEX);
            return;
        }
        User user = (User) session.getAttribute("user");
        if (user == null) {
            ServletUtils.dispatcher(request, response, Page.INDEX);
            return;
        }        
    }

}
